package com.chhuang.ewcrm.thread;

import com.chhuang.ewcrm.comm.CommStartListener;

import static java.lang.Thread.sleep;

/**
 * 红外感应器定时查询类
 */
public class InfraRedThread implements Runnable {

    /**
     * 查询红外是否遮挡发送指令
     */
    private static final String HEX_CODE = "01 05 55 02 5D";

    private final CommStartListener commStartListener;

    private boolean flag = true;

    public InfraRedThread(CommStartListener commStartListener){
        this.commStartListener = commStartListener;
    }

    @Override
    public void run() {
        while (flag){
            commStartListener.send(HEX_CODE);//查询红外是否遮挡发送
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                flag = false;
            }
        }
    }

    public void close(){
        flag = false;
    }
}
